package com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.controller;

import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.entity.DmDsSource;
import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.entity.DmDsSourceEnum;
import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.service.DmDsSourceService;
import com.xnewtech.xplatform.swan.libs.scanner.annotation.PostResource;
import com.xnewtech.xplatform.swan.libs.scanner.stereotype.ApiResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (DmDsSource)表控制层
 *
 * @author makejava
 * @since 2021-09-22 13:19:35
 */

@RestController
@ApiResource(name = "数据源表管理", path = "/dmDsSource")
@Api(tags = "数据源表管理")
public class DmDsSourceController {
    /**
     * 服务对象
     */
    @Resource
    private DmDsSourceService dmDsSourceService;

    /**
     * 新增数据
     *
     * @param dmDsSource 实体
     * @return 新增结果
     */
    @PostResource(name = "添加", path = "/insert")
    @ApiOperation("新增")
    public ResponseEntity<DmDsSource> add(DmDsSource dmDsSource) {
        return ResponseEntity.ok(this.dmDsSourceService.insert(dmDsSource));
    }

    /**
     * 删除数据
     *
     * @param dsId 实体id
     */
    @PostResource(name = "删除", path = "/delete")
    @ApiOperation("删除")
    public void deleteById( Long dsId) {
        this.dmDsSourceService.deleteById(dsId);
    }

    /**
     * 修改数据
     *
     * @param dmDsSource 实体
     * @return 修改结果
     */
    @PostResource(name = "修改", path = "/update")
    @ApiOperation("修改")
    public ResponseEntity<DmDsSource> update(DmDsSource dmDsSource) {

        return ResponseEntity.ok(this.dmDsSourceService.update(dmDsSource));
    }

    /**
     * 查询数据源
     *
     * @param dataType  数据源类型
     * @param dsName    数据源名称
     * @param pageNum   分页数
     * @param pageSize  分页大小
     * @return DmDsSource
     */
    @PostResource(name = "查询", path = "/select")
    @ApiOperation("查询")
    public List<Map<DmDsSource, DmDsSource>> select(@RequestParam(value = "dataType",required = true) DmDsSourceEnum dataType,
                                                    @RequestParam(value = "dsName",required = false) String dsName,
                                                    @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                    @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize) {

        List<Map<DmDsSource, DmDsSource>> mapList = dmDsSourceService.select(dataType, dsName, pageNum, pageSize);
        return mapList;
    }

    /**
     * 通过dsId批量删除数据源
     * @param dsId 多个dsId
     */
    @PostResource(name = "批量删除", path = "/batchDelete")
    @ApiOperation("批量删除")
    public Integer batchDelete(Integer[] dsId) {
        Integer num=dmDsSourceService.batchDelete(dsId);
        return num;
    }
}

